package com.gm.camunda.controller;

import com.gm.camunda.service.ProcessInstanceService;
import com.gmadmin.common.ApiResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * {@code @Author}: zhang liang
 * {@code @Date}: 2022/10/9 17:08
 * {@code @BelongsProject}: gm
 * {@code @BelongsPackage}: com.gm.camunda.controller
 * {@code @Description}: 流程实例
 */
@RestController
@RequestMapping("/processInstance")
public class ProcessInstanceController {

    private final ProcessInstanceService processInstanceService;

    public ProcessInstanceController(ProcessInstanceService processInstanceService) {
        this.processInstanceService = processInstanceService;
    }


    /**
     * 开始流程实例
     * @param processDefinitionKey 流程定义key，从流程获取
     * @param businessKey  自定义初始化事例实例的业务密钥
     * @param initiator  流程发起人
     * @return 结果
     */
    @PostMapping("/startProcess")
    public ApiResponse startProcess(String processDefinitionKey, String businessKey, String initiator) {
        processInstanceService.startProcessInstanceByKey(processDefinitionKey, businessKey, initiator);
        return ApiResponse.ofSuccess();
    }
}
